#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#define STOP '|'
int main(void)
{FILE *fp; 
char ch;
fp = fopen("up.txt", "w");  
    if (!fp) {  
        perror("Failed to open file for writing characters");  
    }  
printf("Enter text to be analyzed (| to terminate):\n");
while ((ch = toupper(getchar())) != STOP)fwrite(&ch, sizeof(ch), 1, fp);
fwrite("|", sizeof(ch), 1, fp);
fclose(fp);  
  
    // 从字符文件中读取数据  
    if ((fp = fopen("up.txt", "r")) == NULL) {  
        printf("fail\n");  
    }  
   while(1){
        fread(&ch, sizeof(char), 1, fp);
        if (ch=='|')
        {
            break;
        }
        printf("%c", ch);  }
    fclose(fp);  
return 0;}